package servlet;

import db.DB;
import model.Liuyan;
import model.User;
import model.good;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Date;

@WebServlet("/addgood")//访问的时候给一个地址,高于3.0版本的包才能这么配地址
public class addgood extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");
        String goodname=req.getParameter("addgoodname");
        Double goodbuy=Double.parseDouble(req.getParameter("addgoodbuy"));
        Double goodsell=Double.parseDouble(req.getParameter("addgoodsell"));
        String goodinfo=req.getParameter("addgoodinfo");

        good gd=new good();
        gd.setGood_name(goodname);
        gd.setpurchase_price(goodbuy);
        gd.setselling_price(goodsell);
        gd.setremarks(goodinfo);

        String datapage = null;
        HttpSession session=req.getSession();

        if(new DB().addgood(gd)){
            datapage = "good";
            session.setAttribute("datapage",datapage);
            resp.sendRedirect("datasystem.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp); }
}

